home *** CD-ROM | disk | FTP | other *** search
- Path: news.NetVision.net.il!news
- From: Moti Saadon <moti@netmanage.co.il>
- Newsgroups: comp.lang.c++
- Subject: [] overloading
- Date: Wed, 24 Jan 96 15:33:27 PDT
- Organization: NetVision LTD.
- Message-ID: <NEWTNews.822526719.31981.moti@motisaad.netmanage.co.il>
- NNTP-Posting-Host: motisaan.netmanage.co.il
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
-
-
- How can help me and tell me why the vc++4.0
-
- dosn't compile the definition of the subscript []operator?
-
- If the subscript is online the compile succes.
-
- -----------------------start code-----------------------------------
- //execption.cpp
-
- #include <stdio.h>
- #include <iostream.h>
-
-
-
-
- template <class Type>
- class Array {
- Type *array;
- int size; //size of the array
- public:
- Array (int sz)
- { array = new Type[size = sz];}
- ~Array () {delete [] array;}
- Type &operator [] (int i);
- /* {
- cout << "\nsize = " << size << " i = " << i << "\n";
- if (i<0 || i>=size)
- throw Range(0, size-1, i);
-
- return array[i];
- }
- */
- };
-
-
-
- //now comes the definition of the subscript operator
- //this code can't compile. why?
- template <class Type>
- Type &Array::operator[] (int i)
- {
- if (i<0 || i>=size)
- throw Range(0, size-1, i);
- return array[i];
- }
-
- -----------------------end code-----------------------------------
-
-